package svmc.stp.hoaitt;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import com.google.gson.Gson;
import com.google.gson.JsonIOException;
// TrinhNX 01/29: Comment code
// Wow, it is great when separated into the smaller classes.
// It is also very good to know how to use the library (gson for example :P good job)
// Rate 8 point
// But it is not the best, to be updated tonight
// Tonight question ;P Static :3.
class WarehouseLocation {
	private double latitude;
	private double longitude;

	public WarehouseLocation(double latitude, double longitude) {
		super(); // no need this (super() do nothing here)
		// What if i write latitude  = this.latitude Or latitude = latitude???
		// Question for tonight.
		this.latitude = latitude; 
		this.longitude = longitude;
	}

}

class Dimensions {
	private double length;
	private double width;
	private double height;

	public Dimensions(double length, double width, double height) {
		super(); // no need this (super() do nothing here)
		this.length = length;
		this.width = width;
		this.height = height;
	}

}

class Product {
	int id;
	String name;
	double price;
	String[] tags;
	Dimensions dimensions;
	WarehouseLocation warehouseLocation;

}

public class ReadJSON {

	public static void main(String[] args) throws JsonIOException, IOException,
			FileNotFoundException {
		
		Gson gson = new Gson();
		
		Product product1 = gson.fromJson(new FileReader("test.json"), Product.class);
		
		System.out.println(product1.name);
		
		
		
		/**
		*	1. Read string from file
		*/
		//		try {
		//			FileReader file = new FileReader(new File("test.json"));
		//			BufferedReader br = new BufferedReader(file);
		//			String temp = null;
		//			StringBuilder sb = new StringBuilder();
		//			while ((temp = br.readLine()) != null) {
		//				sb.append(temp);
		//			}
		//			br.close();
		//			// String file se nam trong sb
		//			System.out.println(sb.toString());
		//			Gson gson = new Gson();
		//			Product product = gson.fromJson(sb.toString(), Product.class);
		//			System.out.println(product.name);
		//		} catch (IOException e) {
		//			System.err.println(e);
		//		}

	}

}
